<template>
	<view>
		<view class="flex align-center justify-between padding-y-16 padding-x-30 bg-fff nav_fixed_top">
			<view @click="goBack()">
				<image src="../../static/img/back.png" style="width: 30rpx;height: 30rpx;margin: 0 auto;"></image>
			</view>
			<view class="radius60 flex1 margin-x-30 padding-x-30 flex align-center" style="background: rgba(102, 102, 102, 0.08);">
				<image src="../../static/img/srh_6.png" style="width: 40rpx;height: 40rpx;"></image>
				<input type="text"  v-model="q.keywords" @confirm="search()" class="fs-26 color-333 margin-left-20 ipt flex1" placeholder="请输入">
			</view>
			<view>
				<image  @click="sjump('/pages/msg/index')" src="../../static/img/msg_6.png"  style="width: 46rpx;height: 46rpx;"></image>
			</view>
		</view>
		<!-- 分类 -->
		<view class="margin-top-20">
			<view class="padding-y-24 bg-fff flex align-center justify-between">
				<view @tap="selarea()" class="flex align-center flex1 justify-center">
					<text :class="filterType == 1 ?'color-zhuse':'color-999'" class="fs-28  margin-right-10">{{area || '区域'}}</text>
					<image :src="filterType == 1  ? '../../static/img/down_on.png':'../../static/img/down.png'" style="width: 30rpx;height: 30rpx;"></image>
				</view>
				<!-- <view class="flex align-center flex1 justify-center">
					<text class="fs-28 color-999 margin-right-10">价格</text>
					<image src="../../static/img/down.png" style="width: 30rpx;height: 30rpx;"></image>
				</view> -->
			</view>
		</view>
		<!-- 分类end -->
		
		<view class="padding-20">
			<view v-for="(item,index) in goodsList" :key='index' @click="jump('/pages/qiuzhi/detail?id='+item.id)" class="bg-fff radius10 padding-x-24 padding-y-30 margin-bottom-30">
				<view class="flex align-center justify-between">
					<text class="fs-30 color-333">{{item.title}}</text>
					<text class="fs-24 color-666">{{item.address}}</text>
				</view>
				<view class="flex align-center justify-between margin-top-30">
					<view>
						<view class="fs-30 color-zhuse">{{item.income}}元 <text class="fs-24 color-999 margin-left-24">·{{item.position}}</text></view>
						<view class="flex align-center margin-top-16">
							<view class="fs-20 color-999 radius10 margin-right-20">{{item.describe}}</view>
							<!-- <view class="fs-20 color-999 radius10 margin-right-20" style="padding: 4rpx 16rpx;border: 1rpx solid #999;">广告</view> -->
							<!-- <view class="fs-20 color-999 radius10 margin-right-20" style="padding: 4rpx 16rpx;border: 1rpx solid #999;">广告</view> -->
							<!-- <view class="fs-20 color-999 radius10 margin-right-20" style="padding: 4rpx 16rpx;border: 1rpx solid #999;">广告</view> -->
						</view>
					</view>
					<view class="public_btn-xs">申请</view>
				</view>
				<view class="flex align-center margin-top-36">
					<image style="width: 70rpx;height: 70rpx;border-radius: 100%;"  :src="item.avatar"></image>
					<view class="margin-left-20">
						<view class="fs-24 color-000">{{item.name}}</view>
						<view class="fs-20 color-999 margin-top-10" style="transform: scale(0.9);">{{item.company_name}}</view>
					</view>
				</view>
			</view>
			
			<view class="nomore" :class="loadStatus" v-if="goodsList.length"></view>
			<empty v-if="goodsList.length < 1"></empty>
			
		</view>
		
	
		<!-- 区域 -->
		<uni-popup ref="area" type="bottom">
			<view class="area_wrap bg-fff padding-40 radius-top30 relative">
				<image class="area_close" src="../../static/img/close_icon.png" mode="aspectFit" @tap="close()"></image>
				<view class="fs-32 fw-bold text-center">请选择地区</view>
				<view class="flex align-center padding-y-30">
					<text class="area_sel text-cut padding-x-16" v-for="(item, index) in arr" :key="index" @tap="selText(item, index)">{{item.label}}</text>
					<text class="area_sel color-zhuse" v-if="hasMore">请选择</text>
				</view>
				<scroll-view scroll-y class="area_box padding-y-40">
					<view class="fs-28 color-333 padding-y-16 text-cut" :class="{'fw-bolder color-zhuse':current == index }" v-for="(item, index) in list" :key="item.value" @tap="toggle(item, index)">
						<image v-if="current == index" class="duihao" src="../../static/img/duihao.png" mode="aspectFit"></image>
						{{item.label}}
					</view>
				</scroll-view>
			</view>
		</uni-popup>
		<!-- 区域end -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				q:{
					category_id:'',
					keywords:'',
					region:'',
					page:1
				},
				hasMore: true,
				loadStatus: '',
				goodsList: [],
				
				list: [],
				area:'',
				arr:[],
				current:-1,
				textCurrent:0,
				
				hasMore:true,
				
				filterType:1
			}
		},
		onLoad(opt) {
			this.q.category_id = opt.id
			this.getList();
			this.init();
		},
		onReachBottom() {
			if(this.hasMore){
				this.q.page += 1;
				this.getList();
			}
		},
		methods:{
			getList(){
				this.isLoading = true;
				this.$api.recruit_list(this.q).then(res=>{
					if(res.code == 1){
						this.isLoading = false;
						this.goodsList = [...this.goodsList, ...res.data.data];
						if (res.data.data.length != 0) {
							this.hasMore = true;
							this.loadStatus = '';
						} else {
							this.hasMore = false;
							this.loadStatus = 'over';
						}
					}
				})
			},
			search(){
				this.q.page = 1;
				this.goodsList = [];
				this.getList();
			},
			
			
			
			// 区域
			reset(){
				this.list = [];
				this.arr = [];
				this.current = -1;
				this.textCurrent = 0;
				this.area = '';
				this.init();
			},
			init(region){
				var data = {
					region: region || ''
				}
				this.$api.getRegion(data).then(res => {
					if(res.code == 1){
						this.list = res.data;
						if(this.list.length > 0){
							this.list.forEach((m,i)=>{
								if(this.arr[this.textCurrent] && m.value == this.arr[this.textCurrent].value){
									this.current = i;
								}
							})
						}
					}else{
						if(res.data.length == 0){
							console.log("----")
							this.hasMore = false
							this.area = this.arr[this.arr.length-1].label;
							this.q.category_id = this.arr[this.arr.length - 1].value;
							this.q.page = 1;
							this.goodsList = [];
							this.getList();
							// this.arr.forEach((item, index)=>{
							// 	this.area += item.label;
							// })
							this.$refs.area.close();
						}else{
							console.log("=====")
							this.hasMore = true
						}
					}
				});
			},
			toggle(item, index){
				this.current = index;
				this.init(item.value);
				this.arr[this.textCurrent] = item;
				if(this.textCurrent+1 < this.arr.length){
					this.arr = this.arr.slice(0, this.textCurrent+1)
				}
				this.textCurrent++;
				this.current = -1;
			},
			selarea(){
				this.$refs.area.open();
				this.filterType = 1;
				if(!this.hasMore){
					if(this.arr.length == 1){
						this.textCurrent = this.arr.length - 1;
						this.init();
					}
					if(this.arr.length > 1){
						this.textCurrent = this.arr.length - 1;
						this.init(this.arr[this.arr.length - 2].value || '');
					}
					if(this.arr.length == 0){
						this.reset();
					}
				}
			},
			selText(item, index){
				this.textCurrent = index;
				if(index == 0){
					this.init();
				}else{
					this.init(this.arr[index-1].value);
				}
			},
			close(){
				if(this.arr.length < 3){
					this.reset();
				}
				this.$refs.area.close();
			},
		}
	}
</script>

<style>
	page{
		background: #f7f7f7;
	}
</style>
<style lang="scss" scoped>
	.ipt{height: 70rpx;}
	.index_icon{width: 56rpx;height: 56rpx;}
</style>
